package com.ruoyi.quartz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quartz.domain.TWareList;
import com.ruoyi.quartz.domain.WareEntry;
import com.ruoyi.quartz.service.ITWareListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/list")
public class TWareListController extends BaseController
{
    private String prefix = "system/list";

    @Autowired
    private ITWareListService tWareListService;

    @RequiresPermissions("system:list:view")
    @GetMapping()
    public String list()
    {
        return prefix + "/list";
    }

    /**
     * 查询【入库单】列表
     */
    @RequiresPermissions("system:list:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TWareList tWareList)
    {
        startPage();
        List<TWareList> list = tWareListService.selectTWareListList(tWareList);
        return getDataTable(list);
    }

    /**
     * 导出【入库单】列表
     */
    @RequiresPermissions("system:list:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TWareList tWareList)
    {
        List<TWareList> list = tWareListService.selectTWareListList(tWareList);
        ExcelUtil<TWareList> util = new ExcelUtil<TWareList>(TWareList.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【入库单】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【入库单】
     */
//    @RequiresPermissions("system:list:add")
//    @Log(title = "【】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody WareEntry wareEntry)
    {
        return toAjax(tWareListService.insertTWareList(wareEntry));
    }

    /**
     * 修改【入库单】
     */
    @RequiresPermissions("system:list:edit")
    @GetMapping("/edit/{wareId}")
    public String edit(@PathVariable("wareId") Long wareId, ModelMap mmap)
    {
        TWareList tWareList = tWareListService.selectTWareListByWareId(wareId);
        mmap.put("tWareList", tWareList);
        return prefix + "/edit";
    }

    /**
     * 修改保存【入库单】
     */
    @RequiresPermissions("system:list:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WareEntry wareEntry)
    {
        return toAjax(tWareListService.updateTWareList(wareEntry));
    }

    /**
     * 删除【入库单】
     */
    @RequiresPermissions("system:list:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tWareListService.deleteTWareListByWareIds(ids));
    }
}